package com.xbongbong.saas.factory.publicrule;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.enums.ClueRuleEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author long
 * @version v1.0
 * @date 2020/12/2 14:55
 * @since v1.0
 */
@Component
public class CheckClueRuleFactory {

    @Resource
    private CheckClueRuleNoCommunicate checkClueRuleNoCommunicate;
    @Resource
    private CheckRuleMaxClueNum checkRuleMaxClueNum;
    @Resource
    private CheckClueRulePrePrincipal checkClueRulePrePrincipal;
    @Resource
    private CheckClueRuleGainRate checkClueRuleGainRate;


    public ICheckClueRule checkClueRuleFactory(Integer ruleType) throws XbbException {

        ClueRuleEnum clueRuleEnum = ClueRuleEnum.getByCode(ruleType);

        switch (clueRuleEnum) {
            case NO_COMMUNICATE_RULE:
                return checkClueRuleNoCommunicate;
            case MAX_CLUE_NUM_RULE:
                return checkRuleMaxClueNum;
            case PRE_PRINCIPAL_RULE:
                return checkClueRulePrePrincipal;
            case GAIN_RATE_RULE:
                return checkClueRuleGainRate;
            default:
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100028, I18nStringConstant.RULE_TYPE_ERROR);
        }
    }
}
